<?php
class LoginAction extends Action {
	public function index() {
		
		// 配置页面显示内容
		$this->assign ( 'title', '后台管理系统' );
		$this->display ();
	}
	
	// 用户登录页面
	public function login() {
		$user_dao = M ( 'User' ); // 参数的User必须首字母大写，否则自动验证功能失效！
		$username = $_POST ['username'];
		$password = $_POST ['password'];
		
		// 查找输入的用户名是否存在
		$condition ['username'] = $username;
		$condition ['password'] = $password;
		
		$user = $user_dao->where ( $condition )->find ();
		
		if ($user) {
			$_SESSION ['user'] = $user;
			$this->redirect ( "Index/index" );
		} else {
			$this->error ( '用户名或密码错误' );
		}
	}
	
	public function logout() {
		unset ( $_SESSION ['user'] );
		$this->redirect ( "Index/index" );
	}
}

?>